package demo;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        Solution solution = new Solution();
        solution.rotate(arr,3);
        System.out.println(Arrays.toString(arr));
    }

}
class Solution {
    public void rotate(int[] nums, int k) {
        while(k>=nums.length){
            k-=nums.length;
        }
        int[] arr = new int[k];
        for (int i = 0; i < k; i++) {
            arr[i]=nums[nums.length-k+i];
        }

        for (int j = nums.length-k-1; j >=0; j--) {
            nums[j+k]=nums[j];
        }
        for (int m = 0; m < k; m++) {
            nums[m]=arr[m];
        }
    }
}